package com.jprocms.module.cms.service.accesspage;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jpro.framework.common.pojo.PageResult;
import com.jprocms.module.cms.controller.admin.accesspage.vo.AccessPagePageReqVO;
import com.jprocms.module.cms.convert.PageConverter;
import com.jprocms.module.cms.dal.dataobject.accesspage.AccessPageDO;
import com.jprocms.module.cms.dal.mysql.accesspage.AccessPageMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;

/**
 * 访问受访页面 Service 实现类
 *
 * @author jprocms
 */
@Service
@Validated
public class AccessPageServiceImpl extends ServiceImpl<AccessPageMapper, AccessPageDO> implements AccessPageService {

    @Resource
    private AccessPageMapper accessPageMapper;
    @Resource
    private PageConverter pageConverter;


    @Override
    public PageResult<AccessPageDO> statPage(AccessPagePageReqVO pageReqVO) {
        final IPage<AccessPageDO> accessPageDOIPage = accessPageMapper.statPage(pageReqVO, new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize()));
        return pageConverter.page(accessPageDOIPage);
    }

    @Transactional(rollbackFor = Exception.class)
    public void deleteByDateString(String dateString, Integer type) {
        accessPageMapper.deleteByDateString(dateString, type);
    }

    @Transactional(rollbackFor = Exception.class)
    public void deleteBeforeDateString(String dataString) {
        accessPageMapper.deleteBeforeDateString(dataString);
    }


}
